<?php

/**
 * @category   mediad2
 * @package    Mediad2_Service
 */
class Mediad2_Service_Admin_Module extends Mediad2_Service_Abstract
{
	/**
	 * 初始化
	 */
	public function init()
	{
		$this->setMapper('Mediad2_Mapper_Module');
		$this->setModel('Mediad2_Model_Module');
	}
	
	/**
	 * 批量删除指定的模块记录
	 *
	 * @param array of $ModuleId
	 * @return boolean return true if no error.
	 */
	public function deleteBatch(array $arrayModuleId)
	{
		if ( count($arrayModuleId) == 0 ) {
			return false;
		}
	
		//构造where条件
		$where = 'moduleId in ( ' . implode(",", $arrayModuleId) . ')';
	
		$mapper = $this->getMapper();
		$dao = $mapper->getDao();
		$result = $dao->delete($where);
		if ($result > 0) {
			return true;
		} else {
			return false;
		}
	}
	
	/**
	 * 返回符合条件的模块名称
	 *
	 * @param string $condition
	 * @return array of ModuleName.
	 */
	public function getModuleName($condition = null)
	{
		$mapper = $this->getMapper();
		$dao = $mapper->getDao();
		$selector = $dao->select();
	
		$cols = array('moduleName');
		$selector->from($selector->getTable(),$cols);
	
		if ($condition != null) {
			$selector->where($condition);
		}
	
		$rows = $dao->fetchAll($selector);
	
		$result = array();
		foreach ($rows as $key => $value) {
			$result[] = strtolower($value->moduleName);
		}
		return $result;
	}
	
}